import * as api from "@/api"
export default {
  namespaced: true,
  state: {
    products: []
  },
  getters: {},
  mutations: {
    SET_PRODUCT(state, paylord) {
      state.products = paylord
    },
    DECREASE_PRODUCT(state, paylord) {
      //   console.log(paylord)
      let target = state.products.find((item) => item.id === paylord.id)
      target.inventory--
    },
    INCREASE_INVENTORY(state, paylord) {
      let target = state.products.find((item) => item.id === paylord.id)
      target.inventory++
    }
  },
  actions: {
    async FETCH_PRODUCT(context) {
      let res = await api.fetchProduct()
      context.commit("SET_PRODUCT", res.data)
    }
  }
}
